package com.nondo.rdp.stock.common;

import java.math.BigDecimal;

public class PriceUtils {
    /**
     * 获取两位数的价格
     *
     * @param price
     * @return
     */
    public static double format(double price) {
        BigDecimal bigDecimal = new BigDecimal(price);
        double result = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        return result;
    }

    /**
     * 根据位数获取价格
     *
     * @param price
     * @param weight
     * @return
     */
    public static double format(double price, int weight) {
        BigDecimal bigDecimal = new BigDecimal(price);
        double result = bigDecimal.setScale(weight, BigDecimal.ROUND_HALF_UP).doubleValue();
        return result;
    }
}
